# Copyright 2023 TikTok Pte. Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exports target PPAM::ppam
#
# Creates variables:
#   PPAM_FOUND : If PPAM was found
#   PPAM_VERSION : the full version number
#   PPAM_VERSION_MAJOR : the major version number
#   PPAM_VERSION_MINOR : the minor version number
#   PPAM_VERSION_PATCH : the patch version number
#   PPAM_BUILD_TYPE : The build type (e.g., "Release" or "Debug")

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

macro(ppam_find_dependency dep)
    find_dependency(${dep})
    if(NOT ${dep}_FOUND)
        if(NOT PPAM_FIND_QUIETLY)
            message(WARNING "Could not find dependency `${dep}` required by this configuration")
        endif()
        set(PPAM_FOUND FALSE)
        return()
    endif()
endmacro()

set(PPAM_FOUND FALSE)
set(PPAM_STATIC_FOUND FALSE)
set(PPAM_SHARED_FOUND FALSE)

set(PPAM_VERSION @PPAM_VERSION@)
set(PPAM_VERSION_MAJOR @PPAM_VERSION_MAJOR@)
set(PPAM_VERSION_MINOR @PPAM_VERSION_MINOR@)
set(PPAM_VERSION_PATCH @PPAM_VERSION_PATCH@)
set(PPAM_BUILD_TYPE @CMAKE_BUILD_TYPE@)

set(PPAM_CARRY_DPCA_PSI @PPAM_CARRY_DPCA_PSI@)
set(PPAM_CARRY_EIGEN @PPAM_CARRY_EIGEN@)
set(PPAM_CARRY_OPENSSL @PPAM_CARRY_OPENSSL@)

ppam_find_dependency(nlohmann_json REQUIRED)

if(NOT PPAM_CARRY_DPCA_PSI)
    ppam_find_dependency(DPCA_PSI REQUIRED)
endif()
if(NOT PPAM_CARRY_EIGEN)
    ppam_find_dependency(Eigen3 REQUIRED)
endif()
if(NOT PPAM_CARRY_OPENSSL)
    ppam_find_dependency(OpenSSL REQUIRED)
endif()

set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
ppam_find_dependency(Threads REQUIRED)

# Add the current directory to the module search path
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

include(${CMAKE_CURRENT_LIST_DIR}/PPAMTargets.cmake)

if(TARGET PPAM::ppam)
    set(PPAM_FOUND TRUE)
    set(PPAM_STATIC_FOUND TRUE)
endif()

if(TARGET PPAM::ppam_shared)
    set(PPAM_FOUND TRUE)
    set(PPAM_SHARED_FOUND TRUE)
endif()

if(PPAM_FOUND)
    if(NOT PPAM_FIND_QUIETLY)
        message(STATUS "PPAM -> Version ${PPAM_VERSION} detected")
    endif()
    if(PPAM_DEBUG AND NOT PPAM_FIND_QUIETLY)
        message(STATUS "Performance warning: PPAM compiled in debug mode")
    endif()

    set(PPAM_TARGETS_AVAILABLE "PPAM -> Targets available:")
    if(PPAM_STATIC_FOUND)
        string(APPEND PPAM_TARGETS_AVAILABLE " PPAM::ppam")
    endif()
    if(PPAM_SHARED_FOUND)
        string(APPEND PPAM_TARGETS_AVAILABLE " PPAM::ppam_shared")
    endif()
    if(NOT PPAM_FIND_QUIETLY)
        message(STATUS ${PPAM_TARGETS_AVAILABLE})
    endif()
else()
    if(NOT PPAM_FIND_QUIETLY)
        message(STATUS "PPAM -> NOT FOUND")
    endif()
endif()
